package com.brand.data.service;

import java.util.Map;

import org.jsoup.Connection;
import org.jsoup.Jsoup;

/**
 * @author scl
 * @date 2018年4月11日 下午2:45:57
 * @version 1.0
 * @description API测试接口
 */
public class AbstractBaseService {
	protected Connection getConnection(String url, Map<String, String> datas, Map<String, String> headers,
			Map<String, String> cookies) {
		Connection connection = Jsoup.connect(url).ignoreContentType(true).timeout(10000);
		if (datas != null) {
			connection.data(datas);
		}
		if (headers != null) {
			connection.headers(headers);
		}
		if (cookies != null) {
			connection.cookies(cookies);
		}
		if (url.startsWith("https")) {
			connection.validateTLSCertificates(false);
		}
		return connection;
	}

	protected Connection getConnection(String url, Map<String, String> datas, Map<String, String> headers) {
		return getConnection(url, datas, headers, null);
	}

	protected Connection getConnection(String url, Map<String, String> datas) {
		return getConnection(url, datas, null);
	}

	protected Connection getConnection(String url) {
		return getConnection(url, null);
	}
}
